package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.AreaDAO;
import com.pojo.Area;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaService extends ServiceImpl<AreaDAO, Area>{

    @Autowired
    private AreaDAO areaDAO;

    /**
     * 根据已选城市查询所有县区
     * @param citycode 城市code
     * @return
     * area 存入redis缓存
     */
    @Cacheable(value = "area")
    public List<Area> findArea(String citycode){
        QueryWrapper queryWrapper = new QueryWrapper();
        if (citycode != null){
            queryWrapper.eq("citycode",citycode);
        }
        List list = areaDAO.selectList(queryWrapper);
        return list;
    }

}
